package com.qj.yantaishan.controller;

import java.util.List;
import com.baomidou.mybatisplus.extension.service.IService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.qj.yantaishan.common.annotation.Log;
import com.qj.yantaishan.common.enums.BusinessType;
import com.qj.yantaishan.domain.OrderPackage;
import com.qj.yantaishan.service.IOrderPackageService;
import com.qj.yantaishan.common.core.controller.BaseController;
import com.qj.yantaishan.common.core.domain.AjaxResult;
import com.qj.yantaishan.common.utils.poi.ExcelUtil;
import com.qj.yantaishan.common.core.page.TableDataInfo;

/**
 * 订单包裹Controller
 * 
 * @author qihe
 * @date 2022-07-22
 */
@RestController
@RequestMapping("/yantaishan/OrderPackage")
public class OrderPackageController extends BaseController
{
    private String prefix = "yantaishan/OrderPackage";

    @Autowired
    private IOrderPackageService orderPackageService;

    @RequiresPermissions("yantaishan:package:view")
    @GetMapping()
    public String package1()
    {
        return prefix + "/package";
    }

    /**
     * 查询订单包裹列表
     */
    @RequiresPermissions("yantaishan:package:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(OrderPackage orderPackage)
    {
        startPage();
        List<OrderPackage> list = orderPackageService.selectOrderPackageList(orderPackage);
        return getDataTable(list);
    }

    /**
     * 导出订单包裹列表
     */
    @RequiresPermissions("yantaishan:package:export")
    @Log(title = "订单包裹", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(OrderPackage orderPackage)
    {
        List<OrderPackage> list = orderPackageService.selectOrderPackageList(orderPackage);
        ExcelUtil<OrderPackage> util = new ExcelUtil<OrderPackage>(OrderPackage.class);
        return util.exportExcel(list, "订单包裹数据");
    }

    /**
     * 新增订单包裹
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存订单包裹
     */
    @RequiresPermissions("yantaishan:package:add")
    @Log(title = "订单包裹", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(OrderPackage orderPackage)
    {
        return toAjax(orderPackageService.insertOrderPackage(orderPackage));
    }

    /**
     * 修改订单包裹
     */
    @RequiresPermissions("yantaishan:package:edit")
    @GetMapping("/edit/{packageId}")
    public String edit(@PathVariable("packageId") Long packageId, ModelMap mmap)
    {
        OrderPackage orderPackage = orderPackageService.selectOrderPackageByPackageId(packageId);
        mmap.put("orderPackage", orderPackage);
        return prefix + "/edit";
    }

    /**
     * 修改保存订单包裹
     */
    @RequiresPermissions("yantaishan:package:edit")
    @Log(title = "订单包裹", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(OrderPackage orderPackage)
    {
        return toAjax(orderPackageService.updateOrderPackage(orderPackage));
    }

    /**
     * 删除订单包裹
     */
    @RequiresPermissions("yantaishan:package:remove")
    @Log(title = "订单包裹", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(orderPackageService.deleteOrderPackageByPackageIds(ids));
    }
}
